{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "d5a6ba48",
   "metadata": {
    "polyglot_notebook": {
     "kernelName": "csharp"
    },
    "vscode": {
     "languageId": "polyglot-notebook"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div><div></div><div></div><div><strong>Installed Packages</strong><ul><li><span>BenchmarkDotnet, 0.15.0</span></li></ul></div></div>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#load \"..\\Extension\\LoadBaseTool.csx\"\n",
    "#r \"nuget: BenchmarkDotnet\"\n",
    "\n",
    "using BenchmarkDotNet.Attributes;\n",
    "using BenchmarkDotNet.Running;"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "polyglot_notebook": {
     "kernelName": "csharp"
    },
    "vscode": {
     "languageId": "polyglot-notebook"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "// Validating benchmarks:\n",
      "//    * No exporters defined, results will not be persisted.\n",
      "\n",
      "// ***** BenchmarkRunner: Start   *****\n",
      "// ***** Found 1 benchmark(s) in total *****\n",
      "// ***** Building 1 exe(s) in Parallel: Start   *****\n",
      "// ***** Done, took 00:00:00 (0 sec)   *****\n",
      "// Found 1 benchmarks:\n",
      "//   SimpleBenchmark.AddNumbers: Job-SWFIEC(Toolchain=InProcessEmitToolchain)\n",
      "\n",
      "Setup power plan (GUID: 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c FriendlyName: 高性能)\n",
      "// **************************\n",
      "// Benchmark: SimpleBenchmark.AddNumbers: Job-SWFIEC(Toolchain=InProcessEmitToolchain)\n",
      "// *** Execute ***\n",
      "// Launch: 1 / 1\n",
      "\n",
      "// Benchmark Process Environment Information:\n",
      "// BenchmarkDotNet v0.15.0\n",
      "// Runtime=.NET 9.0.5 (9.0.525.21509), X64 RyuJIT AVX2\n",
      "// GC=Concurrent Server\n",
      "// HardwareIntrinsics=AVX2,AES,BMI1,BMI2,FMA,LZCNT,PCLMUL,POPCNT,AvxVnni,SERIALIZE VectorSize=256\n",
      "// Job: Job-SWFIEC(Toolchain=InProcessEmitToolchain)\n",
      "\n",
      "OverheadJitting  1: 1 op, 370100.00 ns, 370.1000 us/op\n",
      "WorkloadJitting  1: 1 op, 354100.00 ns, 354.1000 us/op\n",
      "\n",
      "OverheadJitting  2: 16 op, 506600.00 ns, 31.6625 us/op\n",
      "WorkloadJitting  2: 16 op, 809600.00 ns, 50.6000 us/op\n",
      "\n",
      "WorkloadPilot    1: 16 op, 27100.00 ns, 1.6938 us/op\n",
      "WorkloadPilot    2: 32 op, 37600.00 ns, 1.1750 us/op\n",
      "WorkloadPilot    3: 64 op, 54000.00 ns, 843.7500 ns/op\n",
      "WorkloadPilot    4: 128 op, 132800.00 ns, 1.0375 us/op\n",
      "WorkloadPilot    5: 256 op, 187100.00 ns, 730.8594 ns/op\n",
      "WorkloadPilot    6: 512 op, 278600.00 ns, 544.1406 ns/op\n",
      "WorkloadPilot    7: 1024 op, 566800.00 ns, 553.5156 ns/op\n",
      "WorkloadPilot    8: 2048 op, 4374300.00 ns, 2.1359 us/op\n",
      "WorkloadPilot    9: 4096 op, 3065500.00 ns, 748.4131 ns/op\n",
      "WorkloadPilot   10: 8192 op, 9510200.00 ns, 1.1609 us/op\n",
      "WorkloadPilot   11: 16384 op, 8447100.00 ns, 515.5701 ns/op\n",
      "WorkloadPilot   12: 32768 op, 16807400.00 ns, 512.9211 ns/op\n",
      "WorkloadPilot   13: 65536 op, 33466200.00 ns, 510.6537 ns/op\n",
      "WorkloadPilot   14: 131072 op, 67470400.00 ns, 514.7583 ns/op\n",
      "WorkloadPilot   15: 262144 op, 133964300.00 ns, 511.0332 ns/op\n",
      "WorkloadPilot   16: 524288 op, 296116900.00 ns, 564.7982 ns/op\n",
      "WorkloadPilot   17: 1048576 op, 528760500.00 ns, 504.2653 ns/op\n",
      "\n",
      "OverheadWarmup   1: 1048576 op, 1518900.00 ns, 1.4485 ns/op\n",
      "OverheadWarmup   2: 1048576 op, 1510700.00 ns, 1.4407 ns/op\n",
      "OverheadWarmup   3: 1048576 op, 2836800.00 ns, 2.7054 ns/op\n",
      "OverheadWarmup   4: 1048576 op, 1699000.00 ns, 1.6203 ns/op\n",
      "OverheadWarmup   5: 1048576 op, 1504100.00 ns, 1.4344 ns/op\n",
      "OverheadWarmup   6: 1048576 op, 1507900.00 ns, 1.4380 ns/op\n",
      "OverheadWarmup   7: 1048576 op, 2167200.00 ns, 2.0668 ns/op\n",
      "OverheadWarmup   8: 1048576 op, 2650700.00 ns, 2.5279 ns/op\n",
      "OverheadWarmup   9: 1048576 op, 2884500.00 ns, 2.7509 ns/op\n",
      "OverheadWarmup  10: 1048576 op, 1508700.00 ns, 1.4388 ns/op\n",
      "\n",
      "OverheadActual   1: 1048576 op, 1523500.00 ns, 1.4529 ns/op\n",
      "OverheadActual   2: 1048576 op, 2911500.00 ns, 2.7766 ns/op\n",
      "OverheadActual   3: 1048576 op, 1523100.00 ns, 1.4525 ns/op\n",
      "OverheadActual   4: 1048576 op, 1504800.00 ns, 1.4351 ns/op\n",
      "OverheadActual   5: 1048576 op, 2392000.00 ns, 2.2812 ns/op\n",
      "OverheadActual   6: 1048576 op, 1685300.00 ns, 1.6072 ns/op\n",
      "OverheadActual   7: 1048576 op, 1527000.00 ns, 1.4563 ns/op\n",
      "OverheadActual   8: 1048576 op, 1516100.00 ns, 1.4459 ns/op\n",
      "OverheadActual   9: 1048576 op, 2348500.00 ns, 2.2397 ns/op\n",
      "OverheadActual  10: 1048576 op, 1512000.00 ns, 1.4420 ns/op\n",
      "OverheadActual  11: 1048576 op, 1511400.00 ns, 1.4414 ns/op\n",
      "OverheadActual  12: 1048576 op, 1621900.00 ns, 1.5468 ns/op\n",
      "OverheadActual  13: 1048576 op, 1541600.00 ns, 1.4702 ns/op\n",
      "OverheadActual  14: 1048576 op, 1509100.00 ns, 1.4392 ns/op\n",
      "OverheadActual  15: 1048576 op, 1523000.00 ns, 1.4524 ns/op\n",
      "\n",
      "OverheadWarmup   1: 1048576 op, 2775900.00 ns, 2.6473 ns/op\n",
      "OverheadWarmup   2: 1048576 op, 1510300.00 ns, 1.4403 ns/op\n",
      "OverheadWarmup   3: 1048576 op, 1508600.00 ns, 1.4387 ns/op\n",
      "OverheadWarmup   4: 1048576 op, 1510500.00 ns, 1.4405 ns/op\n",
      "OverheadWarmup   5: 1048576 op, 1509800.00 ns, 1.4399 ns/op\n",
      "OverheadWarmup   6: 1048576 op, 1516200.00 ns, 1.4460 ns/op\n",
      "OverheadWarmup   7: 1048576 op, 2794400.00 ns, 2.6649 ns/op\n",
      "OverheadWarmup   8: 1048576 op, 1507200.00 ns, 1.4374 ns/op\n",
      "\n",
      "WorkloadActual   1: 1048576 op, 544838700.00 ns, 519.5987 ns/op\n",
      "WorkloadActual   2: 1048576 op, 533207600.00 ns, 508.5064 ns/op\n",
      "WorkloadActual   3: 1048576 op, 543614100.00 ns, 518.4308 ns/op\n",
      "WorkloadActual   4: 1048576 op, 554935900.00 ns, 529.2281 ns/op\n",
      "WorkloadActual   5: 1048576 op, 577777300.00 ns, 551.0114 ns/op\n",
      "WorkloadActual   6: 1048576 op, 555664400.00 ns, 529.9229 ns/op\n",
      "WorkloadActual   7: 1048576 op, 555516900.00 ns, 529.7822 ns/op\n",
      "WorkloadActual   8: 1048576 op, 534153300.00 ns, 509.4083 ns/op\n",
      "WorkloadActual   9: 1048576 op, 533812900.00 ns, 509.0837 ns/op\n",
      "WorkloadActual  10: 1048576 op, 544684700.00 ns, 519.4518 ns/op\n",
      "WorkloadActual  11: 1048576 op, 537330800.00 ns, 512.4386 ns/op\n",
      "WorkloadActual  12: 1048576 op, 642069100.00 ns, 612.3248 ns/op\n",
      "WorkloadActual  13: 1048576 op, 538616800.00 ns, 513.6650 ns/op\n",
      "WorkloadActual  14: 1048576 op, 570241400.00 ns, 543.8246 ns/op\n",
      "WorkloadActual  15: 1048576 op, 547362800.00 ns, 522.0058 ns/op\n",
      "WorkloadActual  16: 1048576 op, 576432600.00 ns, 549.7290 ns/op\n",
      "WorkloadActual  17: 1048576 op, 573637800.00 ns, 547.0636 ns/op\n",
      "WorkloadActual  18: 1048576 op, 536469200.00 ns, 511.6169 ns/op\n",
      "WorkloadActual  19: 1048576 op, 550828400.00 ns, 525.3109 ns/op\n",
      "WorkloadActual  20: 1048576 op, 622524200.00 ns, 593.6853 ns/op\n",
      "WorkloadActual  21: 1048576 op, 538798000.00 ns, 513.8378 ns/op\n",
      "WorkloadActual  22: 1048576 op, 536112600.00 ns, 511.2768 ns/op\n",
      "WorkloadActual  23: 1048576 op, 536343600.00 ns, 511.4971 ns/op\n",
      "WorkloadActual  24: 1048576 op, 539875400.00 ns, 514.8653 ns/op\n",
      "WorkloadActual  25: 1048576 op, 554755100.00 ns, 529.0557 ns/op\n",
      "WorkloadActual  26: 1048576 op, 546859900.00 ns, 521.5262 ns/op\n",
      "\n",
      "WorkloadResult   1: 1048576 op, 543315200.00 ns, 518.1458 ns/op\n",
      "WorkloadResult   2: 1048576 op, 531684100.00 ns, 507.0535 ns/op\n",
      "WorkloadResult   3: 1048576 op, 542090600.00 ns, 516.9779 ns/op\n",
      "WorkloadResult   4: 1048576 op, 553412400.00 ns, 527.7752 ns/op\n",
      "WorkloadResult   5: 1048576 op, 576253800.00 ns, 549.5584 ns/op\n",
      "WorkloadResult   6: 1048576 op, 554140900.00 ns, 528.4699 ns/op\n",
      "WorkloadResult   7: 1048576 op, 553993400.00 ns, 528.3293 ns/op\n",
      "WorkloadResult   8: 1048576 op, 532629800.00 ns, 507.9554 ns/op\n",
      "WorkloadResult   9: 1048576 op, 532289400.00 ns, 507.6307 ns/op\n",
      "WorkloadResult  10: 1048576 op, 543161200.00 ns, 517.9989 ns/op\n",
      "WorkloadResult  11: 1048576 op, 535807300.00 ns, 510.9857 ns/op\n",
      "WorkloadResult  12: 1048576 op, 537093300.00 ns, 512.2121 ns/op\n",
      "WorkloadResult  13: 1048576 op, 568717900.00 ns, 542.3717 ns/op\n",
      "WorkloadResult  14: 1048576 op, 545839300.00 ns, 520.5529 ns/op\n",
      "WorkloadResult  15: 1048576 op, 574909100.00 ns, 548.2760 ns/op\n",
      "WorkloadResult  16: 1048576 op, 572114300.00 ns, 545.6107 ns/op\n",
      "WorkloadResult  17: 1048576 op, 534945700.00 ns, 510.1640 ns/op\n",
      "WorkloadResult  18: 1048576 op, 549304900.00 ns, 523.8580 ns/op\n",
      "WorkloadResult  19: 1048576 op, 537274500.00 ns, 512.3849 ns/op\n",
      "WorkloadResult  20: 1048576 op, 534589100.00 ns, 509.8239 ns/op\n",
      "WorkloadResult  21: 1048576 op, 534820100.00 ns, 510.0442 ns/op\n",
      "WorkloadResult  22: 1048576 op, 538351900.00 ns, 513.4124 ns/op\n",
      "WorkloadResult  23: 1048576 op, 553231600.00 ns, 527.6028 ns/op\n",
      "WorkloadResult  24: 1048576 op, 545336400.00 ns, 520.0733 ns/op\n",
      "\n",
      "\n",
      "Mean = 521.553 ns, StdErr = 2.716 ns (0.52%), N = 24, StdDev = 13.305 ns\n",
      "Min = 507.053 ns, Q1 = 510.780 ns, Median = 518.072 ns, Q3 = 527.914 ns, Max = 549.558 ns\n",
      "IQR = 17.133 ns, LowerFence = 485.080 ns, UpperFence = 553.614 ns\n",
      "ConfidenceInterval = [511.321 ns; 531.785 ns] (CI 99.9%), Margin = 10.232 ns (1.96% of Mean)\n",
      "Skewness = 0.86, Kurtosis = 2.47, MValue = 2\n",
      "\n",
      "// ** Remained 0 (0.0%) benchmark(s) to run. Estimated finish 2025-05-26 13:21 (0h 0m from now) **\n",
      "Successfully reverted power plan (GUID: 381b4222-f694-41f0-9685-ff5bb260df2e FriendlyName: 平衡)\n",
      "// ***** BenchmarkRunner: Finish  *****\n",
      "\n",
      "// * Export *\n",
      "\n",
      "// * Detailed results *\n",
      "SimpleBenchmark.AddNumbers: Job-SWFIEC(Toolchain=InProcessEmitToolchain)\n",
      "Runtime = ; GC = \n",
      "Mean = 521.553 ns, StdErr = 2.716 ns (0.52%), N = 24, StdDev = 13.305 ns\n",
      "Min = 507.053 ns, Q1 = 510.780 ns, Median = 518.072 ns, Q3 = 527.914 ns, Max = 549.558 ns\n",
      "IQR = 17.133 ns, LowerFence = 485.080 ns, UpperFence = 553.614 ns\n",
      "ConfidenceInterval = [511.321 ns; 531.785 ns] (CI 99.9%), Margin = 10.232 ns (1.96% of Mean)\n",
      "Skewness = 0.86, Kurtosis = 2.47, MValue = 2\n",
      "-------------------- Histogram --------------------\n",
      "[506.546 ns ; 518.654 ns) | @@@@@@@@@@@@@\n",
      "[518.654 ns ; 539.911 ns) | @@@@@@@\n",
      "[539.911 ns ; 552.019 ns) | @@@@\n",
      "---------------------------------------------------\n",
      "\n",
      "// * Summary *\n",
      "\n",
      "BenchmarkDotNet v0.15.0, Windows 11 (10.0.22631.3447/23H2/2023Update/SunValley3)\n",
      "13th Gen Intel Core i5-13400F 2.50GHz, 1 CPU, 16 logical and 10 physical cores\n",
      ".NET SDK 9.0.300\n",
      "  [Host] : .NET 9.0.5 (9.0.525.21509), X64 RyuJIT AVX2\n",
      "\n",
      "Toolchain=InProcessEmitToolchain  \n",
      "\n",
      "| Method     | Mean     | Error    | StdDev   |\n",
      "|----------- |---------:|---------:|---------:|\n",
      "| AddNumbers | 521.6 ns | 10.23 ns | 13.30 ns |\n",
      "\n",
      "// * Legends *\n",
      "  Mean   : Arithmetic mean of all measurements\n",
      "  Error  : Half of 99.9% confidence interval\n",
      "  StdDev : Standard deviation of all measurements\n",
      "  1 ns   : 1 Nanosecond (0.000000001 sec)\n",
      "\n",
      "// ***** BenchmarkRunner: End *****\n",
      "Run time: 00:00:31 (31.65 sec), executed benchmarks: 1\n",
      "\n",
      "Global total time: 00:00:31 (31.66 sec), executed benchmarks: 1\n",
      "// * Artifacts cleanup *\n",
      "Artifacts cleanup is finished\n"
     ]
    }
   ],
   "source": [
    "public class SimpleBenchmark\n",
    "{\n",
    "    [Benchmark]\n",
    "    public int AddNumbers()\n",
    "    {\n",
    "        int sum = 0;\n",
    "        for (int i = 0; i < 1000; i++)\n",
    "            sum += i;\n",
    "        return sum;\n",
    "    }\n",
    "}\n",
    "\n",
    "// Polyglot Notebooks 默认在 Debug 下运行\n",
    "IConfig Config = new BenchmarkDotNet.Configs.DebugInProcessConfig();\n",
    "var summary = BenchmarkRunner.Run<SimpleBenchmark>(Config);"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": ".NET (C#)",
   "language": "C#",
   "name": ".net-csharp"
  },
  "language_info": {
   "name": "python"
  },
  "polyglot_notebook": {
   "kernelInfo": {
    "defaultKernelName": "csharp",
    "items": [
     {
      "aliases": [],
      "name": "csharp"
     }
    ]
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
